﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
namespace CommonTagTime
{
     public static class clsVideo
    {
         public static string GetVideoResource(string link, int w, int h, int autoPlay, int relatedVideo)
         {
             link = ConvertVideoYoutube(link,autoPlay,relatedVideo);
             string result = @"<object height='" + h + "' width='" + w + @"'>
                            <param name='movie' value='" + link + @"'>
                            <param  name='allowFullScreen' value='true'>
                            <param  name='wmode' value='transparent'>
                            <param name='allowscriptaccess' value='always'>  
                            <embed wmode='transparent' type='application/x-shockwave-flash' allowfullscreen='true'  allowscriptaccess='always'
                                src='" + link + @"' height='" + h + "' width='" + w + "' ></object>";
             return result;
         }
         public static string GetVideoResource(string link, int w, int h, int autoPlay, int relatedVideo,string ctrId)
         {
             link = ConvertVideoYoutube(link, autoPlay, relatedVideo);
             string result = @"<object  height='" + h + "' width='" + w + @"'>
                            <param name='movie' value='" + link + @"'>
                            <param name='allowFullScreen' value='true'>
                            <param  name='wmode' value='transparent'>
                            <param name='allowscriptaccess' value='always'>  
                            <embed wmode='transparent' id= '" + ctrId + @"' type='application/x-shockwave-flash' allowfullscreen='true'  allowscriptaccess='always'
                                src='" + link + @"'  height='" + h + "' width='" + w + "'></object>";
             return result;
         }
         public static string ConvertVideoYoutube(string link, int autoPlay, int relatedVideo)
         {
             ////p://www.youtube.com/watch?v=MRY-weqyHus&feature=related
             string result = "http://www.youtube.com/v/{0}&autoplay={1}&rel={2}";
             int indexPara = link.LastIndexOf("?v=");
             if (indexPara > 0)
             {
                 string value = string.Empty;
                 int indexQ = link.IndexOf("&");
                 if(indexQ>0)
                    value = link.Substring(indexPara + 3, indexQ - indexPara-3);
                 else value = link.Substring(indexPara + 3,link.Length-indexPara -3);
                 result = string.Format(result, value,autoPlay,relatedVideo);
 
             }
             return result;
         }
    }
}

